<%@ page language="java" import="com.shop.mall.utils.*,com.shop.mall.dao.impl.*,com.shop.mall.entity.*"
         pageEncoding="utf-8" %>
<%@ page import="java.util.List" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    System.out.println("here is index.jsp ,basePath:" + basePath);
%>
<jsp:include page="../commons/common.jsp" flush="true"/>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>index page</title>
    <meta name="description" content="这是一个 table 页面">
    <meta name="keywords" content="table">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        #box1 {
            margin: 0 auto;
            width: 1166px;
            border: 1px solid blanchedalmond;
        }

        #showGoods {
            width: inherit;
            height: inherit;

        }

        #showGoods ul li {
            text-align: center;
            border: 1px solid blanchedalmond;
            width: 164px;
            float: left;
            list-style: none;
            line-height: 27px;
        }

        .title {
            font-size: 18px;
            font-weight: bold;
        }

        .text {
            line-height: 27px;
            text-align: center;
        }

        .text a {
            padding-left: 30px;
        }
    </style>
    <script type="text/javascript">
        var basePath = '<%=basePath %>';
        <%--var pageNo = ${page.pageNo};--%>
        <%--var totalCount = ${page.totalCount};--%>
        <%--var totalPage = ${page>totalPage};--%>
        <%--var pageSize = ${page.pageSize};--%>
        $(document).ready(function () {
            $("#add").click(function () {
                window.location.href = "addbook.jsp"
            });
            $("#update").click(function () {
                window.location.href = "updatebook.jsp"
            });
            $("#delete").click(function () {
                window.location.href = "deletebook.jsp"
            });
            $("#upload").click(function () {
                window.location.href = "upload.jsp"
            });
            $("#fileList").click(function () {
                window.location.href = "fileList.jsp"
            });
            $("#btn1").click(function () {
                var bookid = $("#bookid").val();
                console.log("bookid：" + bookid);
                if (bookid === '') {
                    alert("请输入图书ID");
                    return;
                }
                $.post(basePath + "/BookServlet?operation=selectBookById?bookid=" + bookid, bookid, function (data, status) {
                    console.log("Data: " + data + "\nStatus: " + status);
                    //alert("Data: " + data + "\nStatus: " + status);
                });
                // $.ajax({
                //     type: "get",
                //     dataType: "text",
                //     url: basePath + '/BookServlet?operation=selectBookById?bookid=' + bookid,
                //     data: bookid,
                //     success: function (data) {
                //         if (data !== "") {
                //             console.log("bookid：" + bookid)
                //         }
                //     },
                //     error : function(errorData){
                //         console.log("ajax请求异常：" + errorData)
                //     }
                // });
            })
        });
    </script>
</head>
<%
    String cpage = request.getParameter("cpage");
    if (cpage == null) {
        cpage = "1";
    }
    int pages = Integer.parseInt(cpage);
    BookDaoImpl bd = new BookDaoImpl();
    Pages p = bd.showAll(pages, 5);
    List<Book> list = (List<Book>) p.getList();
%>
<body>
<div class="am-cf admin-main">
    <!-- sidebar start -->
    <jsp:include page="../commons/menu.jsp" flush="true"/>
    <!-- sidebar end -->

    <!-- content start -->

    <div class="admin-content">
        <div class="admin-content-body">
            <div class="am-cf am-padding am-padding-bottom-0">
                <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">图书列表</strong> /
                    <small>Table</small>
                </div>
            </div>

            <hr>

            <div class="am-g">
                <div class="am-u-sm-12 am-u-md-6">
                    <div class="am-btn-toolbar">
                        <div class="am-btn-group am-btn-group-xs">
                            <button type="button" id="add" class="am-btn am-btn-primary"><span class="am-icon-plus"></span>
                                新增
                            </button>
                            <button type="button" id="update" class="am-btn am-btn-secondary" disabled="disabled"><span
                                    class="am-icon-save"></span> 修改
                            </button>
                            <button type="button" id="delete" class="am-btn am-btn-warning"><span
                                    class="am-icon-trash-o"></span> 删除
                            </button>
                            <button type="button" id="upload" class="am-btn am-btn-success"><span
                                    class="am-icon-save"></span> 文件上传
                            </button>
                            <button type="button" id="fileList" class="am-btn am-btn-primary"><span
                                    class="am-icon-archive"></span> 文件下载
                            </button>
                        </div>
                    </div>
                </div>
                <div class="am-u-sm-12 am-u-md-3">
                    <div class="am-input-group am-input-group-sm">
                        <input type="text" class="am-form-field" name="bookid" id="bookid">
                        <span class="am-input-group-btn">
                        <button class="am-btn am-btn-default" type="button" id="btn1">查询</button>
                    </span>
                    </div>
                </div>
            </div>

            <div class="am-g">
                <div class="am-u-sm-12">
                    <form class="am-form">
                        <table class="am-table am-table-striped am-table-hover table-main">
                            <div id="showGoods">
                                <ul class="title">
                                    <li>书名</li>
                                    <li>图书编号</li>
                                    <li>出版社</li>
                                    <li>出版日期</li>
                                    <li>价格</li>
                                    <li>创建人ID</li>
                                    <li>操作</li>
                                </ul>
                                <%
                                    for (Book b : list) {
                                %>
                                <ul>
                                    <li><%=b.getBookname() %>
                                    </li>
                                    <li><%=b.getIsbn()%>
                                    </li>
                                    <li><%=b.getPublisher() %>
                                    </li>
                                    <li><%=b.getPublisdate() %>
                                    </li>
                                    <li><%=b.getPrice() %>
                                    </li>
                                    <li><%=b.getUserid() %>
                                    </li>
                                    <li>
                                        <a href="deletebook.jsp?id=<%=b.getId()%>">删除</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        <a href="updatebook.jsp?id=<%=b.getId()%>">修改</a>
                                    </li>
                                </ul>
                                <%

                                    }
                                %>
                                <tr>
                                    <td class="text">
                                        共 <span style="color:red"><%=p.getTotalRecord() %></span>条记录
                                        当前页:<span style="color:red"><%=p.getCurrentPage()%>/<%=p.getTotalPage()%></span>
                                        <a href="index.jsp?cpage=1">首页</a>
                                        <a href="index.jsp?cpage=<%=p.getUpPageNum()%>">上一页</a>
                                        <a href="index.jsp?cpage=<%=p.getNextPageNum()%>">下一页</a>
                                        <a href="index.jsp?cpage=<%=p.getEndPageNum()%>">尾页</a>
                                    </td>
                                </tr>

                            </div>
                        </table>
                    </form>
                </div>

            </div>
        </div>
        <jsp:include page="../commons/footer.jsp" flush="true"/>
    <!-- content end -->
</div>

</div>
</html>
